import { App, ComponentPublicInstance } from 'vue'
import axios from 'axios'

export default function handleError (Vue: App, baseUrl: string) {
  if (!baseUrl) {
    return
  }
  Vue.config.errorHandler = (
    err: unknown,
    instance: ComponentPublicInstance | null,
    info: string
  ) => {
    // send error info
    axios.post(`${baseUrl}/report-error`, {
      err,
      instance,
      info
    })
  }
}
